home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickTime / Sample Code / QuickTime™ codec example / examplecodec.a next >
Encoding:
Text File  |  1997-02-26  |  5.4 KB  |  259 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        examplecodec.a
  3. ;
  4. ;    Copyright:    © 1991-1996 by Apple Computer, Inc., all rights reserved.
  5.  
  6.  
  7.  
  8.  
  9.   if &type('NOASM') = 'UNDEFINED' then
  10. NOASM        EQU        0
  11.   endif
  12.  
  13.   IF NOASM = 0 THEN
  14.  
  15.             BLANKS    ON
  16.             STRING    ASIS
  17.             MACHINE    MC68030
  18.             CASE    ON            
  19.  
  20.  
  21.     macro    
  22.     pin    &d
  23.     
  24.     spl        d2
  25.     cmp.w    d2,&d
  26.     sgt        d0
  27.     or.b    d0,&d
  28.     and.w    d2,&d
  29.  
  30.     endm
  31.     
  32.  
  33.     macro
  34.     do_yuv_rgb
  35.  
  36.     lsl.w    #2,d5                ; make y an 8-bit value
  37.     move.w    d5,d6                ; get Y
  38.     add.w    d7,d6                ; get Y+U (red)
  39.     pin        d6
  40.     swap    d6                    ; move red to position
  41.     move.w    d5,d6                ; get Y
  42.     add.w    d4,d6                ; get Y+V (blue)
  43.     pin        d6
  44.  
  45.     swap    d5                    ; extend Y to fixed
  46.     clr.w    d5                    ; clear fract part
  47.     sub.l    0(a4,d6.w*4),d5        ; sub blue (weighted) from Y
  48.     swap    d6
  49.     sub.l    0(a3,d6.w*4),d5        ; sub red (weighted) from Y
  50.     swap    d6                    ; fix result
  51.     swap    d5                    ; convert back to int
  52.     tst.w    d5
  53.     pin        d5
  54.     move.b    0(a5,d5.w),d2        ; get green from Y->G table
  55.     bfins    d2,d6{16:8}            ; put green in position
  56.  
  57.     endm
  58.  
  59.  
  60.  
  61.  
  62.  
  63. argc        equ    16
  64. data        equ    16+4
  65. baseAddr    equ    12+4
  66. rowBytes    equ    10+4
  67. len            equ    8+4
  68. glob        equ    4+4
  69.  
  70.  
  71. DECOMPRESSSTRIP    PROC    EXPORT
  72.  
  73. ;pascal void 
  74. ;DecompressStrip(char *data,char *baseAddr,short rowBytes,short len,SharedGlobals *sg)
  75.  
  76.  
  77.     link    a6,#0                ; create stack frame
  78.     movem.l    d3-d7/a2-a5,-(sp)    ; save standard registers
  79.  
  80.     move.l    glob(a6),a0
  81.     move.l    (a0),a3                ; base of red weight table
  82.     tst.l    a3
  83.     beq        bail                ; no table - we should really deal with this case
  84.     move.l    (a3),a3                ; dereference
  85.     tst.l    a3
  86.     beq        bail                ; no table - we should really deal with this case
  87.     move.l    a3,a4                ; base of blue weight table
  88.     adda.w    #512*4,a4
  89.     move.l    4(a0),a5            ; base of inverse green weight table
  90.     move.l    (a5),a5                ; dereference
  91.     tst.l    a3
  92.     beq        bail                ; no table - we should really deal with this case
  93.     move.l    data(a6),a0            ; start of the YUV data
  94.     move.l    baseAddr(a6),a1        ; pixel baseaddr
  95.     move.w    rowBytes(a6),a2        ; row bytes
  96.     move.w    len(a6),d1            ; number of blocks to do
  97.     
  98.     
  99.     addq.w    #1,d1
  100.     lsr.w    #1,d1                ; make len number of blocks
  101.     subq.w    #1,d1                ; fix len for dbra
  102.     clr.w    d2                    ; clear mask word
  103. loop:
  104.     move.l    (a0)+,d3            ; get first data word
  105.     move.b    (a0)+,d4            ; get V
  106.     ext.w    d4                    ; V is a word
  107.     lsl.w    #2,d4
  108.     move.b    d3,d7                ; get U
  109.     ext.w    d7                    ; U is a word
  110.     lsl.w    #2,d7
  111.     
  112.     bfextu    d3{0:6},d5            ; get first Y
  113.     do_yuv_rgb
  114.     move.l    d6,(a1)+            ; write rgb pixel
  115.     
  116.     bfextu    d3{6:6},d5            ; get next Y
  117.     do_yuv_rgb
  118.     move.l    d6,(a1)                ; write rgb pixel
  119.     adda.w    a2,a1                ; bump to next scanline
  120.     subq.l    #4,a1                ; back up one
  121.     
  122.     bfextu    d3{12:6},d5            ; get next Y
  123.     do_yuv_rgb
  124.     move.l    d6,(a1)+            ; write rgb pixel
  125.     
  126.     bfextu    d3{18:6},d5            ; get last Y
  127.     do_yuv_rgb
  128.     move.l    d6,(a1)+            ; write rgb pixel
  129.     suba.w    a2,a1                ; backup to first scanline
  130.         
  131.     dbra    d1,loop                ; continue for whole row
  132.  
  133. bail:
  134.     movem.l    (sp)+,d3-d7/a2-a5    ; restore registers
  135.     unlk    a6                    ; ditch stack frame
  136.     move.l    (sp)+,a0            ; get return address
  137.     add.l    #argc,sp            ; ditch incoming arguments
  138.     jmp    (a0)                    ; return to caller
  139.  
  140.     endproc
  141.     
  142.  
  143.  
  144.  
  145.     macro
  146.     do_rgb_yuv
  147.                                 ; enter with 888 rgb in d0.l
  148.                                 ; exit with 8 bit y in do.w
  149.  
  150.     move.w    d0,d3                ; get blue
  151.     and.w    d6,d3                ; strip blue
  152.     add.w    d3,d4                ; accum blue
  153.     swap     d4                    ; point to red_accum
  154.  
  155.     move.w    d0,d2
  156.     lsr.w    #8,d2                ; get green
  157.     
  158.     swap    d0                    ; get red
  159.     and.w    d6,d0                ; strip red
  160.     add.w    d0,d4                ; accum red
  161.     swap     d4                    ; point to blue_accum
  162.  
  163.     move.l    0(a3,d0.w*4),d0        ; weighted red
  164.     add.l    0(a4,d2.w*4),d0        ; weighted green
  165.     add.l    0(a5,d3.w*4),d0        ; weighted blue
  166.     swap    d0                    ; get integer part of Y
  167.     cmp.w    d6,d0                ; see if > 255
  168.     blt.s    @1
  169.     move.w    d6,d0                ; if so mask it
  170. @1:
  171.     add.w    d0,d7                ; accum Y
  172.     lsr.w    #2,d0                ; convert Y to 6-bits
  173.     
  174.     
  175.     endm
  176.  
  177.  
  178.  
  179. COMPRESSSTRIP    PROC    EXPORT
  180.  
  181. ;pascal void 
  182. ;CompressStrip(char *data,char *baseAddr,short rowBytes,short len,SharedGlobals *sg)
  183.  
  184.  
  185.     link    a6,#0                ; create stack frame
  186.     movem.l    d3-d7/a2-a5,-(sp)        ; save standard registers
  187.     
  188.  
  189.     move.l    glob(a6),a0
  190.     move.l    (a0),a3                ; base of red weight table
  191.     tst.l    a3
  192.     beq        bail                ; no table - we should really deal with this case
  193.     move.l    (a3),a3                ; dereference
  194.     tst.l    a3
  195.     beq        bail                ; no table - we should really deal with this case
  196.     move.l    a3,a4                
  197.     adda.w    #256*4,a4            ; base of green weight table
  198.     move.l    a4,a5                
  199.     adda.w    #256*4,a5            ; base of blue weight table
  200.     move.l    data(a6),a0            ; start of the YUV data
  201.     move.l    baseAddr(a6),a1        ; pixel baseaddr
  202.     move.w    rowBytes(a6),a2        ; row bytes
  203.     move.w    len(a6),d1            ; number of blocks to do
  204.     
  205.     addq.w    #1,d1
  206.     lsr.w    #1,d1                ; make len number of blocks
  207.     subq.w    #1,d1                ; fix len for dbra
  208.     clr.w    d6                    ; clear mask word
  209.     st        d6                    ; set mask
  210. loop:
  211.  
  212.     clr.l    d4                    ; clear blue_accum and red_accum
  213.     clr.w    d7                    ; clear y_accum
  214.     move.l    (a1)+,d0            ; read rgb pixel
  215.     do_rgb_yuv
  216.     bfins    d0,d5{0:6}    
  217.     
  218.     move.l    (a1),d0                ; read rgb pixel
  219.     do_rgb_yuv
  220.     bfins    d0,d5{6:6}    
  221.  
  222.     adda.w    a2,a1                ; bump to next scanline
  223.     subq.l    #4,a1
  224.     
  225.     move.l    (a1)+,d0            ; read rgb pixel
  226.     do_rgb_yuv
  227.     bfins    d0,d5{12:6}    
  228.     
  229.     move.l    (a1)+,d0            ; read rgb pixel
  230.     do_rgb_yuv
  231.     bfins    d0,d5{18:6}    
  232.     suba.w    a2,a1                ; back up to first scanline
  233.     
  234.     swap    d4                    ; get red accum
  235.     sub.w    d7,d4                ; R-Y = U
  236.     asr.w    #4,d4                ; normalize 
  237.     move.b    d4,d5                ; combine in dword
  238.     move.l    d5,(a0)+            ; write out Ys and U
  239.     
  240.     swap    d4                    ; get blue accum
  241.     sub.w    d7,d4                ; Y-B = V
  242.     asr.w    #4,d4                ; normalize
  243.     move.b    d4,(a0)+            ; write out V
  244.  
  245.     dbra    d1,loop                ; continue for whole row
  246. bail:
  247.     movem.l    (sp)+,d3-d7/a2-a5    ; restore registers
  248.     unlk    a6                    ; ditch stack frame
  249.     move.l    (sp)+,a0            ; get return address
  250.     add.l    #argc,sp            ; ditch incoming arguments
  251.     jmp    (a0)                    ; return to caller
  252.  
  253.     endproc
  254.     
  255.  
  256.   ENDIF        ; HAS_ASM = 1
  257.  
  258.     end
  259.